var filterlist = cg_getPref("string","extensions.optimizegoogle.misc.filterlist","");
filterlist = filterlist.replace(/\s/g, " ");
filterlist = filterlist.replace(/'/g, "\\'");
//var filterlist = '';
//Used when streaming new results - script not needed for those pages.
var disable = href.match(/#disable-userscript$/);
text += "var textarr = new Object("+textarr.toSource()+");";
text += "OptimizeGoogle.showAdPreviews();\n";
// Google web search
if ( href.match(/^http:\/\/[^\/]+\/(search|#hl|cse|webhp|custom|unclesam|linux|bsd|mac|microsoft|intl)/)) {
// only if necessarry
if (!disable) {
if (cg_getPref("bool","extensions.optimizegoogle.web.remove-ads",false)) {
text += "OptimizeGoogle.removeSponsoredLinksById(new Array('tpa1','tpa2','tpa3','spa1','mbEnd','tads'));\n";
text += "OptimizeGoogle.removeSponsoredLinksRight();\n";
text += "OptimizeGoogle.removeInternalAds();\n";
}
if (cg_getPref("bool","extensions.optimizegoogle.web.search-links",true)) {
text += "OptimizeGoogle.addOtherWebSearches('"+cg_createUrls('websearch')+"');\n";
}
}
if (cg_getPref("bool","extensions.optimizegoogle.web.removeclicktrack",false)) {
text += "OptimizeGoogle.removeUrlClickTrack();\n";
}
if (cg_getPref("bool","extensions.optimizegoogle.web.filter",true)) {
text += "OptimizeGoogle.filterWebsitesFromSearch('"+filterlist+"','"+cg_getPref("string","extensions.optimizegoogle.misc.filtercolor", "#aaaaaa")+"');\n";
}
if (cg_getPref("bool","extensions.optimizegoogle.web.save",false)) {
text += "OptimizeGoogle.addBookmarks('"+cg_getPref("string","extensions.optimizegoogle.web.save-handler", "bookmark")+"');\n";
}
if (cg_getPref("bool","extensions.optimizegoogle.web.counter",false)) {
text += "OptimizeGoogle.addCountSearchResults();\n";
}
if (cg_getPref("bool","extensions.optimizegoogle.web.history",false)) {
text += "OptimizeGoogle.addWayBackMachine();\n";
}
if (cg_getPref("bool","extensions.optimizegoogle.web.favicons",false)) {
text += "OptimizeGoogle.addFavicons();\n";
}
if (cg_getPref("bool","extensions.optimizegoogle.web.searchwiki",false)) {
text += "OptimizeGoogle.removeSearchWiki();\n";
}
if ("en-US" == 'zh-CN') {
text += "OptimizeGoogle.bypassChineseFirewall();\n";
}
}
// only if necessarry
if (!disable) {
// Google web search
if (href.match(/^http:\/\/[^\/]+\/(search|#hl)/)) {
if (cg_getPref("bool","extensions.optimizegoogle.web.auto-page",false)) {
text += "OptimizeGoogle.addAutoPager();\n";
}
}
if ((href.match(/^http:\/\/[^\/]+\/$/) || href.match(/^http:\/\/[^\/]+\/(search|#hl|custom|firefox|webhp|unclesam|linux|bsd|mac|microsoft|ig)/))) {
if (cg_getPref("bool","extensions.optimizegoogle.web.focus",false)) {
text += "OptimizeGoogle.addSearchFieldFocus();\n";
}
if (cg_getPref("bool","extensions.optimizegoogle.web.suggest",true)) {
text += "OptimizeGoogle.addGoogleSuggest();\n";
}
}
}
// Google image search
if (href.match(/^http:\/\/[^\/]+\/images/)) {
// only if necessarry
if (!disable) {
if (cg_getPref("bool","extensions.optimizegoogle.images.image-links",true)) {
text += "OptimizeGoogle.addOtherImageSearches('"+cg_createUrls('imagesearch')+"');\n";
}
if (cg_getPref("bool","extensions.optimizegoogle.images.auto-page",false)) {
text += "OptimizeGoogle.addAutoPager();\n";
}
if (cg_getPref("bool","extensions.optimizegoogle.images.remove-ads",false)) {
text += "OptimizeGoogle.removeSponsoredLinksImages();\n";
}
}
if (cg_getPref("bool","extensions.optimizegoogle.images.rewrite-links",true)) {
text += "OptimizeGoogle.pointLinksToImages();\n";
}
}
// Google Blog search
if (href.match(/^http:\/\/[^\/]+\/blogsearch/)) {
if (cg_getPref("bool","extensions.optimizegoogle.blogs.blog-links",true)) {
text += "OptimizeGoogle.addOtherBlogSearches('"+cg_createUrls('blogsearch')+"');\n";
}
if (cg_getPref("bool","extensions.optimizegoogle.blogs.removeclicktrack",false)) {
text += "OptimizeGoogle.removeUrlClickTrack();\n";
}
}
// Google Groups
if (href.match(/^http:\/\/[^\/]+\/group\//)) {
if (cg_getPref("bool","extensions.optimizegoogle.groups.remove-ads",false)) {
text += "OptimizeGoogle.removeSponsoredLinksFrame();\n";
}
}
if (href.match(/^http:\/\/[^\/]+\/groups/)) {
if (cg_getPref("bool","extensions.optimizegoogle.groups.remove-ads",false)) {
text += "OptimizeGoogle.removeSponsoredLinksRight();\n";
}
}
// Google News
if (href.match(/^http:\/\/[^\/]+\/news/)) {
if (cg_getPref("bool","extensions.optimizegoogle.news.news-links",true)) {
text += "OptimizeGoogle.addOtherNewsSearches('"+cg_createUrls('newssearch')+"');\n";
}
}
if (href.match(/^http:\/\/[^\/]+\/(news|nwshp)/) || href.match(/^http:\/\/news\.google\./)) {
if (cg_getPref("bool","extensions.optimizegoogle.news.filter",false)) {
text += "OptimizeGoogle.filterWebsitesFromNews('"+filterlist+"','"+cg_getPref("string","extensions.optimizegoogle.misc.filtercolor", "#aaaaaa")+"');\n";
}
if (cg_getPref("bool","extensions.optimizegoogle.news.removeclicktrack",false)) {
text += "OptimizeGoogle.removeUrlClickTrack();\n";
}
}
// Google Shopping
if (href.match(/^http:\/\/[^\/]+\/(froogle|products)/)) {
if (cg_getPref("bool","extensions.optimizegoogle.froogle.remove-ads",false)) {
text += "OptimizeGoogle.removeSponsoredLinksProducts();\n";
}
if (cg_getPref("bool","extensions.optimizegoogle.froogle.products-links",true)) {
text += "OptimizeGoogle.addOtherProductSearches('"+cg_createUrls('productsearch')+"');\n";
}
}
// Reader
if (href.match(/^http:\/\/[^\/]+\/reader/) && !href.match(/^http:\/\/[^\/]+\/reader\/(api|perf)/)) {
if (cg_getPref("bool","extensions.optimizegoogle.reader.secure",false)) {
text += "OptimizeGoogle.secureGoogle();\n";
}
}
// History
if (href.match(/^http:\/\/[^\/]+\/(history|bookmarks)/)) {
if (cg_getPref("bool","extensions.optimizegoogle.history.secure",false)) {
text += "OptimizeGoogle.secureGoogle();\n";
}
}
// Google Answers
if (href.match(/^http:\/\/[^\/]+\/answers/)) {
if (cg_getPref("bool","extensions.optimizegoogle.answers.remove-ads",false)) {
text += "OptimizeGoogle.removeSponsoredLinksFrame();\n";
}
}
// Google Book Search
if (href.match(/^http:\/\/[^\/]+\/(print|books)/)) {
if (cg_getPref("bool","extensions.optimizegoogle.print.remove-ads",false)) {
text += "OptimizeGoogle.removeSponsoredLinksRight();\n";
text += "OptimizeGoogle.removeSponsoredLinksPrint();\n";
text += "OptimizeGoogle.removeSponsoredLinksById(new Array('buy','buy_content'));\n";
}
if (cg_getPref("bool","extensions.optimizegoogle.print.restore-menu",true)) {
text += "OptimizeGoogle.restoreGooglePrint();\n";
}
if (cg_getPref("bool","extensions.optimizegoogle.print.book-links",true)) {
text += "OptimizeGoogle.addOtherBookReviews('"+cg_createUrls('booksearch')+"');\n";
}
}
// Google Calendar
if (href.match(/^http:\/\/[^\/]+\/calendar/)) {
if (cg_getPref("bool","extensions.optimizegoogle.calendar.secure",false)) {
text += "OptimizeGoogle.secureGoogle();\n";
}
}
// Google Video Search
if (href.match(/^http:\/\/[^\/]+\/videosearch/)) {
if (cg_getPref("bool","extensions.optimizegoogle.video.video-links",true)) {
text += "OptimizeGoogle.addOtherVideoSearches('"+cg_createUrls('videosearch')+"');\n";
}
}
// Gmail
if (href.match(/^http[s]?:\/\/g?mail\.google\.[a-z\.]+\/(g?mail|hosted|a\/)/)) {
if (cg_getPref("bool","extensions.optimizegoogle.gmail.secure",true)) {
text += "OptimizeGoogle.secureGoogle();\n";
}
if (cg_getPref("bool","extensions.optimizegoogle.gmail.remove-ads",false)) {
// Gmail 1.0
text += "OptimizeGoogle.removeSponsoredLinksByIdGmail(new Array('ra','rc','rp','rb'));\n";
// Gmail 2.0
text += "OptimizeGoogle.removeSponsoredLinksGmail();\n";
}
if (cg_getPref("bool","extensions.optimizegoogle.gmail.hidespam",false)) {
text += "OptimizeGoogle.hideGmailSpam('"+stringbundle.getString("gmail-spam")+"');\n";
}
if (cg_getPref("bool","extensions.optimizegoogle.gmail.monospace",false)) {
text += "OptimizeGoogle.useMonoSpaceFont();\n";
}
if (cg_getPref("bool","extensions.optimizegoogle.gmail.hidechat",false)) {
// Gmail 1.0
text += "OptimizeGoogle.hideID('nb_2');\n";
// Gmail 2.0
text += "OptimizeGoogle.hideClass('a3hTGd');\n";
}
if (cg_getPref("bool","extensions.optimizegoogle.gmail.hideinvite",false)) {
text += "OptimizeGoogle.hideID('nb_1');\n";
text += "OptimizeGoogle.hideID('ip');\n";
// Gmail 2.0
text += "OptimizeGoogle.hideClass('I94Sdc');\n";
}
}
// Google Maps
if (href.match(/^http:\/\/[^\/]+\/(local|maphp)/) || href.match(/^http:\/\/(local|maps)\.google\.[a-z\.]+\//)) {
if (cg_getPref("bool","extensions.optimizegoogle.local.remove-ads",false)) {
text += "OptimizeGoogle.removeSponsoredLinksLocal();\n";
}
}
// Docs & Spreadsheets
if (href.match(/^http:\/\/(docs|spreadsheets)\.google\.[a-z\.]+\//)) {
if (cg_getPref("bool","extensions.optimizegoogle.docs.secure",false)) {
text += "OptimizeGoogle.secureGoogle();\n";
}
}
// Cookies
if (href.match(/^http:\/\/[^\/]+\/(search|#hl)/)) {
if (cg_getPref("bool","extensions.optimizegoogle.misc.anonymizeUID",false)) {
text += "OptimizeGoogle.anonymizeGoogleUID();\n";
}
}
if (href.match(/google\.[a-z\.]+\//)) {
if (cg_getPref("bool","extensions.optimizegoogle.cookies.enableDefaultPreferences",false)) {
text += "OptimizeGoogle.defaultPreferences(";
if (cg_getPref("bool","extensions.optimizegoogle.cookies.enableSafeSearch",false)) {
text += "'" + cg_getPref("string","extensions.optimizegoogle.cookies.SafeSearch","") + "',";
} else { text += "'',"; }
if (cg_getPref("bool","extensions.optimizegoogle.cookies.enableSearchLanguage",false)) {
if (cg_getPref("string","extensions.optimizegoogle.cookies.searchAnyOrSelected","any")=="any") {
text += "'empty',";
} else {
text += "'" + cg_getPref("string","extensions.optimizegoogle.cookies.searchLanguage","") + "',";
}
} else { text += "'',"; }
if (cg_getPref("bool","extensions.optimizegoogle.cookies.enableInterfaceLanguage",false)) {
text += "'" + cg_getPref("string","extensions.optimizegoogle.cookies.interfaceLanguage","") + "',";
} else { text += "'',"; }
if (cg_getPref("bool","extensions.optimizegoogle.cookies.enableResultsPerPage",false)) {
text += "'" + cg_getPref("string","extensions.optimizegoogle.cookies.ResultsPerPage","") + "',";
} else { text += "'',"; }
if (cg_getPref("bool","extensions.optimizegoogle.cookies.enableResultsWindow",false)) {
text += "'" + (cg_getPref("bool","extensions.optimizegoogle.cookies.OpenSearchResultsInNewWindow",false)?"1":"empty") + "',";
} else { text += "'',"; }
if (cg_getPref("bool","extensions.optimizegoogle.cookies.enableSuggest",false)) {
text += "'" + (cg_getPref("bool","extensions.optimizegoogle.cookies.suggest",false)?"1":"empty") + "'";
} else { text += "''"; }
text += ");\n";
}
}
// YouTube
if (href.match(/youtube\.[a-z\.]+\//)) {
if (cg_getPref("bool","extensions.optimizegoogle.youtube.remove-ads",false)) {
text += "OptimizeGoogle.removeSponsoredLinksYouTube();\n";
}
}
}
// Google Cache
if (href.match(/\/(search)\?q=cache:/)) {
if (cg_getPref("bool","extensions.optimizegoogle.cache.continue",false)) {
text += "OptimizeGoogle.cacheContinue();\n";
}
}
if (!(/\.(js|css|xml|rss|pdf)$/.test(href))) {
if (cg_getPref("bool","extensions.optimizegoogle.misc.removeGoogleAnalytics",false)) {
text += "OptimizeGoogle.anonymizeGoogleAnalytics();\n";
}
}
//Check that the originalTarget has content (ie. is not just a script page)
var hasContent = e.originalTarget.evaluate("//div", e.originalTarget, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue
//Use the old insertion if possible (doesn't work with AJAX pages).
if (text.length > 0 && e.originalTarget.body && hasContent) {
var scriptElm = e.originalTarget.createElement("script");